import 'package:chathouse/util/base_utils.dart';
import 'package:chathouse/util/font_utils.dart';
import 'package:chathouse/widgets/form_widgets/widget_paras.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../constant/my_color.dart';

class MyInputWidget extends StatefulWidget {
  String? title;
  Widget? leftIcon;
  String? placeholder;
  bool? obscureText;
  TextEditingController? controller;
  TextStyle? textStyle;
  TextInputType? keyboardType;
  List<TextInputFormatter>? inputFormatters;
  bool? isShoweYe;

  MyInputWidget(
      {this.title,
      this.leftIcon,
      this.placeholder,
      this.obscureText,
      this.controller,
      this.textStyle,
      this.keyboardType,
      this.inputFormatters,
      this.isShoweYe = false,
      Key? key})
      : super(key: key);

  @override
  State<MyInputWidget> createState() => _MyInputWidgetState();
}

class _MyInputWidgetState extends State<MyInputWidget> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        widget.title == null
            ? Container()
            : Text(
                widget.title!,
                style: widget.textStyle ??
                    getTextStyle(18.sp,
                        color: Colors.black, fontType: FontType.DEFAULT),
              ).setContainer(margin: EdgeInsets.only(bottom: 4.w)),
        Container(
          height: INPUT_ITEM_HEIGHT.w,
          padding: EdgeInsets.symmetric(horizontal: 12.w),
          decoration: BoxDecoration(
              border: Border.all(color: MyColors.gary_155155155, width: 1.w),
              borderRadius: BorderRadius.circular(INPUT_ITEM_BORDER_RADIUS.w)),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              widget.leftIcon ?? Container(),
              Expanded(
                  child: TextField(
                inputFormatters: widget.inputFormatters,
                keyboardType: widget.keyboardType,
                controller: widget.controller,
                obscureText: widget.obscureText ?? false,
                style: getTextStyle(16.sp,
                    color: Colors.black, fontType: FontType.MID),
                decoration: InputDecoration(
                  hintText: widget.placeholder,
                  hintStyle: getTextStyle(16.sp,
                      color: MyColors.gary_155155155, fontType: FontType.MID),
                  border: InputBorder.none,
                ),
              )),
              InkWell(onTap: (){
                widget.obscureText = widget.obscureText == true ? false : true;
                setState(() {

                });
              }, child: Visibility(visible: widget.isShoweYe ?? false, child: const Icon(Icons.remove_red_eye,size: 16,)))
            ],
          ),
        )
      ],
    );
  }
}
